package threading;

public class ThreadDemo9 {
    public static boolean isQuit = false;
    public static void main(String[] args) {
        //boolean isQuit = false;//变量捕获
        //java要求变量捕获，捕获的变量必须是final或者“实际final"
        //变量没有用final修饰，但是代码中并没有做出修改
        Thread t = new Thread( () -> {
            while(!isQuit) {
                System.out.println("hello t");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("t 线程终止");
        });
        t.start();
        // 在主线程中，修改isQuit
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        isQuit = true;
    }
}


